<?php 
 // nusoap.php 
	require_once('lib/nusoap.php');
    function getdata(){
		 include("connect/connect.php");
		mysql_select_db("military",$c);
		mysql_query("set names utf8");
        $sql="select min(code_acc) as minpk,max(code_acc) as maxpk from event where senddscc <> 1";
		$rs=mysql_query($sql);
		$result = mysql_fetch_array($rs);
		$minpk=$result["minpk"];
		$maxpk=$result["maxpk"];
		$sql = "select code_acc,(case when left(date_format(date_acc,'%Y%m%d'),4)<'2550' then  concat(left(date_format(date_acc,'%Y%m%d'),4)+543,right(date_format(date_acc,'%Y%m%d'),4)) else date_format(date_acc,'%Y%m%d') end) as date_acc,time_format(time_acc,'%H%i') as time_acc,right(code_acc,8) as plcid_acc,type_acc1,type_acc2,type_acc3,cause,point_xy,point_x,point_y,trans,weapon1,weapon2,weapon3,weapon4,weapon5,weapon6,weapon7,weapon8,num_loss,num_dth,num_wnd,commt from event  where code_acc between '$minpk' and '$maxpk'";
		//echo $sql;
		$rs=mysql_query($sql);
		$str_return="";	//$str_return="code_acc,date_acc,time_acc,plcid_acc,type_acc1,type_acc2,type_acc3,cause,point_xy,point_x,point_y,trans,weapon1,weapon2,weapon3,weapon4,weapon5,weapon6,weapon7,weapon8,num_loss,num_dth,num_wnd,commt;";
		while ($result = mysql_fetch_array($rs)){//ǹٻҧ text 
			$str_return=$str_return.$result["code_acc"].",".$result["date_acc"].",".$result["time_acc"].",".$result["plcid_acc"].",".$result["type_acc1"].",".$result["type_acc2"].",".$result["type_acc3"].",".$result["cause"].",".$result["point_xy"].",".$result["point_x"].",".$result["point_y"].",".$result["trans"].",".$result["weapon1"].",".$result["weapon2"].",".$result["weapon3"].",".$result["weapon4"].",".$result["weapon5"].",".$result["weapon6"].",".$result["weapon7"].",".$result["weapon8"].",".$result["num_loss"].",".$result["num_dth"].",".$result["num_wnd"].",".$result["commt"].";";
		}
		//
		$tempY=date("Y");
		if($tempY<"2550"){
			$tempY=(int)$tempY+543;
		}
		$datetime_send= $tempY.date("-m-d-H:i");
		$sql="update event set senddscc=1,datetime_send='$datetime_send' where code_acc between '$minpk' and '$maxpk'";
		//echo "<br>".$sql;
		$rs=mysql_query($sql);
		// end 
		return $str_return;
	}

	function getMilitaryEvent($name){ 
		return getdata();
	} 

 	$ws_server = new soap_server; // 
	//configureWSDL Soap-Server WSDL File  
$ws_server->configureWSDL('getMilitaryEventWSDL','http://localhost/dsccmis/datasource_webservice/');
 
$ws_server->register('getMilitaryEvent',array('name'=>'xsd:string'),array('militaryevent'=>'xsd:string'),'http://localhost/dsccmis/datasource_webservice/','http://localhost/dsccmis/datasource_webservice','rpc','encoded','send militaryevent');

// Use the request try to invoke the service 
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $ws_server->service($HTTP_RAW_POST_DATA); 
//echo getdata();

?> 
